﻿using HCQ2_IBLL;
using HCQ2_Model;
using HCQ2_Model.VRDD.InputDto._0623;
using HCQ2_Model.VRDD.OutputDto._0623;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace HCQ2_BLL
{
    public partial class T_VRDDCircleBaseServiceBLL: IT_VRDDCircleBaseServiceBLL
    {
        /// <summary>
        ///  按商品或店铺获取服务信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<ServiceByProduct> GetServiceByProduct(InputServiceByProduct param)
        {
            List<ServiceByProduct> result = new List<ServiceByProduct>();
            List<OutputServiceByProduct> list = DBSession.IT_VRDDCircleBaseServiceDAL.GetServiceByProduct(param);
            list?.ForEach(o =>
            {
                ServiceByProduct temp = new ServiceByProduct
                {
                    id = o.id,
                    issue_date = o.issue_date,
                    voice_len = o.voice_len,
                    bs_type = o.bs_type,
                    rel_id = o.rel_id,
                    rel_name=o.rel_name,
                    file_id = o.file_id,
                    file_name = o.file_name,
                    is_read = o.is_read
                };
                if (!string.IsNullOrEmpty(o.voice_url))
                    temp.voice_url = o.voice_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                //缩略图
                List<T_DocBagFileRecord> photoOption = DBSession.IT_DocBagFileRecordDAL.Select(s => s.file_id == o.file_id);
                if (photoOption.Count > 0)
                    photoOption.ForEach(s => s.file_url = s.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))));
                temp.photoOption = photoOption;
                //关联商品缩略图
                if (o.rel_id > 0)
                {
                    List<T_DocBagFileRecord> relOption = DBSession.IT_DocBagFileRecordDAL.Select(s => s.file_id == o.rel_id);
                    if (relOption.Count > 0)
                        relOption.ForEach(s => s.file_url = s.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))));
                    temp.relOption = relOption;
                }
                result.Add(temp);
            });
            return result;
        }
        /// <summary>
        ///  按位置获取服务信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<ServiceByProduct> GetServiceByGPS(InputServiceByGPS param)
        {
            List<ServiceByProduct> result = new List<ServiceByProduct>();
            var list = DBSession.IT_VRDDCircleBaseServiceDAL.GetServiceByGPS(param);
            list?.ForEach(o =>
            {
                ServiceByProduct temp = new ServiceByProduct
                {
                    id = o.id,
                    issue_date = o.issue_date,
                    voice_len = o.voice_len,
                    bs_type = o.bs_type,
                    rel_id = o.rel_id,
                    rel_name=o.rel_name,
                    file_id = o.file_id,
                    file_name=o.file_name,
                    is_read = o.is_read
                };
                if (!string.IsNullOrEmpty(o.voice_url))
                    temp.voice_url = o.voice_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                //缩略图
                List<T_DocBagFileRecord> photoOption = DBSession.IT_DocBagFileRecordDAL.Select(s => s.file_id == o.file_id);
                if (photoOption.Count > 0)
                    photoOption.ForEach(s => s.file_url = s.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))));
                temp.photoOption = photoOption;
                if (o.rel_id > 0)
                {
                    //关联商品缩略图
                    List<T_DocBagFileRecord> relOption = DBSession.IT_DocBagFileRecordDAL.Select(s => s.file_id == o.rel_id);
                    if (relOption.Count > 0)
                        relOption.ForEach(s => s.file_url = s.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))));
                    temp.relOption = relOption;
                }
                result.Add(temp);
            });
            return result;
        }
    }
}